<?php
/*
+ ----------------------------------------------------------------------------------------------------+
|        e107 website system 
|        Plugin Meta File :  e107_plugins/lightbox/e_meta.php
|        Email: support@free-source.net
|        $Revision: 330 $
|        $Date: 2007-02-12 23:22:29 +0200 (Mon, 12 Feb 2007) $
|        $Author: secretr $
|        Copyright Corllete Lab ( http://www.clabteam.com ) under GNU GPL License (http://gnu.org)
|        Support Sites : http://www.free-source.net/ | http://dev.e107bg.org/
+----------------------------------------------------------------------------------------------------+
*/
if (!defined('e107_INIT')) { exit; }
    //varset fix - varset from 0.77

    function lbvarset(&$val,$default='',$testvalue=false) {
    	if (isset($val)) {
    		return (!$testvalue || $val) ? $val : $default;
    	}
    	return $default;
    }

define('LB_VERSION', '1.3');
$lb_path = e_PLUGIN.'lightbox/';
include_lan($lb_path."languages/".e_LANGUAGE.".php");

		echo "\n<script type='text/javascript'>\n";
		echo "<!--\n";
		echo "var fileLoadingImage =        '".$lb_path."src/images/loading.gif';\n";
		echo "var fileBottomNavCloseImage = '".$lb_path."src/images/close.gif';\n";
		echo "var resizeSpeed = ".lbvarset($pref['lightb_rspeed'], 7, true).";\n";
		echo "var borderSize = ".lbvarset($pref['lightb_bsize'], 10, true).";\n";
		echo "var lbLan1 = '".LB_LAN_1."';\n";
		echo "var lbLan2 = '".LB_LAN_2."';\n";
		echo "var lbLan3 = '".LB_LAN_3."';\n";
		echo "// -->\n";
		echo "</script>";
		
	echo '
		<!-- Lightbox CSS -->
        <link rel="stylesheet" href="'.$lb_path.'src/css/lightbox.css" type="text/css" media="screen" />
        <!-- Lightbox Prototype and Scriptaculous -->
		<script src="'.$lb_path.'src/js/prototype.js" type="text/javascript"></script>
		<script src="'.$lb_path.'src/js/scriptaculous.js?load=effects'.($pref['lightb_window'] ? ',window' : '').'" type="text/javascript"></script>
		<!-- Lightbox JS -->
		<script src="'.$lb_path.'src/js/lightbox.js" type="text/javascript"></script>
	';
	//v.1.2
	//server check - detect if dhtml window is available:
	//example: 
    //$lbactive = lbvarset($pref['lightb_window'], false, true);
	if($pref['lightb_window']) {
    	echo '
    		<!-- Window default CSS (required) -->
    		<link href="'.$lb_path.'src/css/themes/default.css" rel="stylesheet" type="text/css" />
    		<!-- Window theme (optional) -->
    		'.($pref['lightb_wtheme'] ? '<link href="'.$lb_path.'src/css/themes/'.$pref['lightb_wtheme'].'.css" rel="stylesheet" type="text/css" />' : '').'
    		<!-- Lightbox shared JS -->
        ';
    	
        //client check: detect the lb existence with some js code in your plugins
        //exampe: 
        //if(typeof lbWindowLib != 'undefined' && lbWindowLib) 
        //  { your code here; }
        // Window js documentation - http://prototype-window.xilinus.com/documentation.html
        // Aculo's script documentation - http://wiki.script.aculo.us/scriptaculous/
        // Prototype documentation - http://www.prototypejs.org/api
    	echo "
            <script type='text/javascript'>
            <!--
            var lbWindowLib = true; 
            var contentWin=null;
            //f-ajax file; w-window width; ttl - window title
            function e107Window(f,s,w,h,ttl){                
                if (contentWin != null) { 
                	e107alert('','".$tp->toJS(LB_LAN_39)."',200); 
                } else { 
                	if(!w) w=350;
                    if(!h) h=400; 
                    contentWin = new Window('e107_win', 
                							{".($pref['lightb_wtheme'] ? "className: '{$pref['lightb_wtheme']}', " : '')."resizable: true, 
                                                hideEffect:Effect.Fade, showEffect:Effect.Appear, minWidth: w, minHeight: h,
                                                title: ttl
                                            });
                    if(!s && f) {
                        contentWin.setAjaxContent(f, {method: 'get'});
                    } else {
                        contentWin.getContent().update(s);
                    }
                    contentWin.setDestroyOnClose();
                    contentWin.showCenter(); 
                                    	
                    // Set up a windows observer
                    lbObserver = { onDestroy: function(eventName, win) 
                    				{ if (win == contentWin) 
                    					{ 	
                    						contentWin = null; 
                                            Windows.removeObserver(this); 
                    					} 
                    				} 
                    			} 
                    Windows.addObserver(lbObserver);
                }
            }
            function e107confirm(f,s,w){               
                if(!s && f) {
                    var fcont = {url: f, options: {method: 'get'}};
                } else {
                    var fcont = s;
                }
                Dialog.confirm(fcont,
                    {   windowParameters: {".($pref['lightb_wtheme'] ? "className: '{$pref['lightb_wtheme']}'," : '' )." width:w},
                        okLabel: '".$tp->toJS(LB_LAN_7)."', cancelLabel: '".$tp->toJS(LB_LAN_8)."',
                        ok: function(win) {return true;}, cancel: function(win) {return false;},
                        buttonClass: 'button'
                    });
            }
            function e107alert(f,s,w){ 
                if(!s && f) {
                    var fcont = {url: f, options: {method: 'get'}};
                } else {
                    var fcont = s;
                }              
                Dialog.alert(fcont,
                    {windowParameters: {".($pref['lightb_wtheme'] ? "className: '{$pref['lightb_wtheme']}'," : '' )." width:w},
                        okLabel: '".$tp->toJS(LB_LAN_7)."',
                        ok: function(win) {return true;},
                        buttonClass: 'button'
                    });
            }
            // -->
            </script>
            ";
    } else {
    	//lightbox window lib disabled
        echo "
            <script type='text/javascript'>
            <!--
                var lbWindowLib = false; 
            // -->
            </script>
            ";
    }
    
   //lighbox window - eval lbBBcode from bbcode handler
   function lbBBcode($class) {
       global $pref, $e107, $tp, $IMAGES_DIRECTORY, $FILES_DIRECTORY, $PLUGINS_DIRECTORY,$ADMIN_DIRECTORY;
       //js - collects all values from the ajax generated window content and creates bbcode insertion string
       if(check_class($class) && $pref['lightb_window']) {       
            $txt = "
                <script type='text/javascript'>
                <!--
                //lightbox bbwindow specific
                function lbBBConfirm(dummy){                
                    if(!lbWindowLib) return;
                    var dobj = new Date();
                    var rndget = dobj.getTime();
                    e107Window('".e_PLUGIN."lightbox/ajax_bb.php?' + rndget,'',450,370,'".$tp->toJS(LB_LAN_35)."');
                }
                //lightbox add text function
                function addLightbox(mod) {
                    if(!e107_selectedInputArea) {
                        e107alert('','".$tp->toJS(LB_LAN_36)."',350);
                        return false;
                    }
                    var imgurl='';
                    var thurl='';
                    if(mod=='advanced') {
                        var imgid = document.getElementById('lb_imgsel');
                        if(imgid.value){
                            imgurl = imgid.value;
                            imgurl = imgurl.replace('".e_IMAGE_ABS."','{e_IMAGE}');
                            imgurl = imgurl.replace('".e_FILE_ABS."','{e_FILE}');
                            imgurl = imgurl.replace('".e_PLUGIN_ABS."','{e_PLUGIN}');
                            imgurl = imgurl.replace('".e_ADMIN_ABS."','".e_ADMIN."');
                        }
                        var thimgid = document.getElementById('lb_thimgsel');
                        if(thimgid.value) {
                            thurl = thimgid.value;
                            thurl = thurl.replace('".e_IMAGE_ABS."','{e_IMAGE}');
                            thurl = thurl.replace('".e_FILE_ABS."','{e_FILE}');
                            thurl = thurl.replace('".e_PLUGIN_ABS."','{e_PLUGIN}');
                            thurl = thurl.replace('".e_ADMIN_ABS."','".e_ADMIN."');
                        }
                        var lbthtext = document.getElementById('lb_athtext') ? document.getElementById('lb_athtext').value : '';
                        var lbtitle = document.getElementById('lb_atitle') ? document.getElementById('lb_atitle').value : '';
                        var lbg = document.getElementById('lb_agroup') ? document.getElementById('lb_agroup').value : '';
                        var lbf = document.getElementById('lb_afloat') ? document.getElementById('lb_afloat').value : '';
                    } else {
                        var imgid = document.getElementById('lb_img');
                        imgurl = imgid.value ? imgid.value : '';
                        if(imgurl) {
                            imgurl = imgurl.replace('".$e107->http_path.$IMAGES_DIRECTORY."','{e_IMAGE}');
                            imgurl = imgurl.replace('".e_IMAGE_ABS."','{e_IMAGE}');
                            imgurl = imgurl.replace('".$e107->http_path.$FILES_DIRECTORY."','{e_FILE}');
                            imgurl = imgurl.replace('".e_FILE_ABS."','{e_FILE}');
                            imgurl = imgurl.replace('".$e107->http_path.$PLUGINS_DIRECTORY."','{e_PLUGIN}');
                            imgurl = imgurl.replace('".e_PLUGIN_ABS."','{e_PLUGIN}');
                            imgurl = imgurl.replace('".$e107->http_path.$ADMIN_DIRECTORY."','".e_ADMIN."');
                            imgurl = imgurl.replace('".e_ADMIN_ABS."','".e_ADMIN."');
                        }
                        var thimgid = document.getElementById('lb_thimg');
                        thurl = thimgid.value ? thimgid.value : '';
                        if(thurl) {
                            thurl = thurl.replace('".$e107->http_path.$IMAGES_DIRECTORY."','{e_IMAGE}');
                            thurl = thurl.replace('".e_IMAGE_ABS."','{e_IMAGE}');
                            thurl = thurl.replace('".$e107->http_path.$FILES_DIRECTORY."','{e_FILE}');
                            thurl = thurl.replace('".e_FILE_ABS."','{e_FILE}');
                            thurl = thurl.replace('".$e107->http_path.$PLUGINS_DIRECTORY."','{e_PLUGIN}');
                            thurl = thurl.replace('".e_PLUGIN_ABS."','{e_PLUGIN}');
                            thurl = thurl.replace('".$e107->http_path.$ADMIN_DIRECTORY."','".e_ADMIN."');
                            thurl = thurl.replace('".e_ADMIN_ABS."','".e_ADMIN."');
                        }
                        var lbthtext = document.getElementById('lb_thtext') ? document.getElementById('lb_thtext').value : '';
                        var lbtitle = document.getElementById('lb_title') ? document.getElementById('lb_title').value : '';
                        var lbg = document.getElementById('lb_group') ? document.getElementById('lb_group').value : '';
                        var lbf = document.getElementById('lb_float') ? document.getElementById('lb_float').value : '';
                    }

                    if(imgurl == '' || imgurl == 'http://') {
                        e107alert('','".$tp->toJS(LB_LAN_37)."',350);
                        return false;
                    }     
                                         
                    if(!lbthtext) lbthtext = '".str_replace("'", "\'", LB_LAN_35a)."';
                    thurl = thurl? '[img]' + thurl + '[/img]' : lbthtext;
                    addtext('[lightbox=' + imgurl + '|' + lbtitle + '|' + lbg + '|' + lbf + ']' + thurl + '[/lightbox]');
                    return true;
                }
                // -->
                </script>
                ";
        } else {
            //not enough permissions - switch to standart insertion mod
            $txt = "
                <script type='text/javascript'>
                <!--
                //lightbox bbwindow specific
                function lbBBConfirm(dummy){                
                   addtext('[lightbox=image_url|title|group|float][/lightbox]');
                }
                // -->
                </script>
            ";
       }
       return $txt; 
    }
?>